# Button with tooltip
# And also a message box
# Updated: Three argument types of QPushButtons
# QPushButton(parent=None), QPushButton(text, [parent=None]), QPushButton(icon, text, [parent=None])

import sys
from PySide import QtGui, QtCore

class ButtonWithTooltip(QtGui.QWidget):
    def __init__(self):
        # super() lets us avoid using the name of the base class explicitly. In 2.7, super is used as below
        super(ButtonWithTooltip, self).__init__()
        # but in 3.x, super can be used as below, which is cleaner and more Java like
        # super().__init__()

        # Create a tooltip for the main window
        QtGui.QToolTip.setFont(QtGui.QFont("SansSerif", 10))
        self.setToolTip('This is a <b>QWidget</b> widget')

        # Create a button and then set a tooltip for it
        btn = QtGui.QPushButton("Button", self) # Self is the parent name
        btn.setToolTip('This is a <b>QPushButton</b> widget')
        btn.resize(btn.sizeHint())      # sizeHint() returns a recommended size of a button
        btn.move(50, 50)                # move() the button on the window to the selected location

        quitBtn = QtGui.QPushButton("Quit", self)
        quitBtn.clicked.connect(QtCore.QCoreApplication.instance().quit)
        quitBtn.resize(quitBtn.sizeHint())
        quitBtn.move(50, 80)

        btnMsg = QtGui.QPushButton("Click Me!", self)
        btnMsg.move(50, 20)
        btnMsg.clicked.connect(self.showMsgBox)

        # Setting up the window and assigning a tooltip to it
        self.setGeometry(400, 400, 250, 150)
        self.setWindowTitle("Tooltips")


    def showMsgBox(self):
        msgbox = QtGui.QMessageBox.information(self, "Title of MsgBox", "This is your message",
                                               QtGui.QMessageBox.Yes | QtGui.QMessageBox.No | QtGui.QMessageBox.Ok,
                                               QtGui.QMessageBox.No)
        if msgbox == QtGui.QMessageBox.Yes:
            print("yes")
        elif msgbox == QtGui.QMessageBox.No:
            print("No")
        elif msgbox == QtGui.QMessageBox.Ok:
            print("OK")


if __name__ == "__main__":
    appObject = QtGui.QApplication(sys.argv)
    ex = ButtonWithTooltip()
    ex.show()
    sys.exit(appObject.exec_())

